#include "StdAfx.h"
#include "GalconServer.h"
#include <boost\bind.hpp>
GalconServer::GalconServer(boost::asio::io_service& service, 
                           boost::asio::ip::tcp::endpoint& endpoint)
                           : m_ioService(service)
                           , m_acceptor(service, endpoint)
                           , m_room(service)
{
   GalconSessionPtr new_session(new GalconSession(service, m_room));
   m_acceptor.async_accept(new_session->GetSocket(),
      boost::bind(&GalconServer::handle_accept, this, new_session,
      boost::asio::placeholders::error));
}

GalconServer::~GalconServer()
{
}

void GalconServer::handle_accept(GalconSessionPtr session, const boost::system::error_code &error)
{
   if (!error)
   {
      session->Start();
      GalconSessionPtr new_session(new GalconSession(m_ioService, m_room));
      m_acceptor.async_accept(new_session->GetSocket(),
         boost::bind(&GalconServer::handle_accept, this, new_session,
         boost::asio::placeholders::error));
   }
}